package com.example.coffeejava.Controller;

import com.example.coffeejava.Dto.Result;
import com.example.coffeejava.Entity.Type;
import com.example.coffeejava.Service.TypeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/type")
public class TypeController {
    @Resource
    private TypeService typeService;

    @PostMapping("/addorupdate")
    public Result addorupdate(@RequestBody  Type type) {
        if (type.getId() == null) {
            System.out.println(type);
            typeService.save(type);
        } else {
            typeService.updateById(type);
        }
        return Result.ok("成功");

    }
    @GetMapping("/list")
    public Result list(Integer pageNum,Integer pageSize,String keyword){
       return Result.ok(typeService.getlist(pageNum,pageSize,keyword));

    }
    @GetMapping("/delete")
    public Result delete(String id){
        typeService.removeById(id);
        return Result.ok("成功");
    }
    @GetMapping("/all")
    public Result all(){
        return Result.ok(typeService.list());
    }
}
